var num = 2;

function addtr(){
	var content='<tr  class="gradeX" id="'+num+'">'
               +'<td><input type="text" ></td>'
               +'<td><input type="text" ></td>'
               +'<td><input type="text" ></td>'
               +'<td><input type="text" ></td>'
               +'<td><input type="text" ></td>'
               +'<tr>'
     $('#child').append($(content));
	num++
}
function deletetr(){
	if(num>2){
		num--
		$('#'+num).remove();
	}
	
}
function findrole(state){
	$.ajax({
		url:'/role/findBystate',
		type:'get',
		data:{'state':state},
		dataType:'json',
		success:function(res){
			for (var i = 0; i < res.length; i++) {
				content='<option value="'+res[i].roleId+'">'+res[i].roleName+'</option>';
				$('#role').append($(content));
			}
		},
		error:function(){
			layer.msg("连接失败")
		}
	})
}
function addreturn(){
	var customer = $('#listform').find('input:eq(0)').val();
	var phone = $('#listform').find('input:eq(1)').val();
	var roleid = $('#listform').find('select').val();
	console.log(roleid)
	$.ajax({
		url:'/return/add',
		type:'post',
		data:{'customer':customer,'phone':phone,'roleid':roleid},
		dataType:'json',
		success:function(res){
			var hid = res;
			for (var i = 1; i <num; i++) {
				var ordernum = $('#'+i).find('input:eq(0)').val();
				var devicecode = $('#'+i).find('input:eq(1)').val();
				var number = $('#'+i).find('input:eq(2)').val();
				var sales = $('#'+i).find('input:eq(3)').val();
				var reason = $('#'+i).find('input:eq(4)').val();
				console.log(ordernum)
				$.ajax({
					url:'/returnchild/add',
					type:'post',
					data:{'ordernum':ordernum,'devicecode':devicecode,'num':number,'sales':sales,'reason':reason,'hid':hid},
					dataType:'json',
					success:function(res){
						if(res.success){
							window.location.reload();
						}
						else{
							layer.msg(res.msg)
						}
					},
					error:function(){
						layer.msg('连接失败')
					}
				})
			}
		},
		error:function(){
			layer.msg('连接失败')
		}
	})
}